/*
 * Class: StateAdapter
 * Created by: Mary Joy Pascual
 * Date Created: 06/20/2014
 * Company: Netsuite
*/
package com.netsuite.adapter;

import com.netsuite.helper.CountryHelper;
import com.netsuite.helper.ErrorHelper;
import com.netsuite.logger.LoggerImp;
import com.netsuite.pojo.StatePOJO;
import com.netsuite.webservices.lists.accounting_2014_1.State;

public class StateAdapter {

	private static String CLASS_NAME = StateAdapter.class.getName();
	
	public static State setState(StatePOJO statePojo) throws ErrorHelper {
		
		LoggerImp.startLog(CLASS_NAME, "setState() - StatePOJO to State");
		
		State state = new State();
		state.setInternalId(statePojo.getInternalId());
		state.setCountry(CountryHelper.countryFromString(statePojo.getCountry()));
		if(state.getCountry().equals(null)){
			throw new ErrorHelper(CLASS_NAME, statePojo.getCountry() + " is an invalid country");
		}

		state.setFullName(statePojo.getStateName());
		state.setShortname(statePojo.getShortName());
		
		LoggerImp.endLog(CLASS_NAME, "setState() - State to StatePOJO");
		
		return state;
		
	}
	
	public static StatePOJO setState(State state) throws ErrorHelper {
		
		LoggerImp.startLog(CLASS_NAME, "setState() - State to StatePOJO");
		
		StatePOJO statePOJO = new StatePOJO();
		statePOJO.setInternalId(state.getInternalId());
		statePOJO.setCountry(state.getCountry().toString());
		statePOJO.setStateName(state.getFullName());
		statePOJO.setShortName(state.getShortname());
		
		LoggerImp.endLog(CLASS_NAME, "setState() - State to StatePOJO");
		
		return statePOJO;
	}
	
	
}
